home *** CD-ROM | disk | FTP | other *** search
/ Whiteline: Alpha / Whiteline Alpha.iso / vision / magiceye / ddd / bprnt.c next >
Encoding:
C/C++ Source or Header  |  1994-09-07  |  3.0 KB  |  180 lines

  1. /*------------------------------------
  2. | Big-print:
  3. | Texte auf Din A 4 Druckern ausgeben,
  4. | die größer als ein Blatt sind.
  5. |
  6. |
  7. --------------------------------------*/
  8. #include <stdio.h>
  9. #include <string.h>
  10. #include <stdlib.h>
  11.  
  12. #include "..\wwlib.src\file_io.h"
  13.  
  14.  
  15. #define PAPER_ROW    72    /* Reihen        */
  16. #define PAPER_CLM    80    /* Spalten        */
  17.  
  18.  
  19. #define max(a, b) ((a) >  (b) ? (a) : (b))
  20. #define min(a, b) ((a) <= (b) ? (a) : (b))
  21.  
  22. /*------------
  23. | Eingabe-File
  24. --------------*/
  25. char *text;
  26.  
  27. /*----------
  28. | Text-Größe
  29. ------------*/
  30. int cc, rc;
  31.  
  32.  
  33. /*----------
  34. | Prototypen
  35. ------------*/
  36. void get_text_size( char *t );
  37. void print_text( void );
  38. void print_page( int r, int c);
  39.  
  40.  
  41. main(int argc, char **argv)
  42. {
  43.     char p[130];
  44.     char n[130];
  45.     char *t;
  46.  
  47.     if( argc != 2)
  48.     {    printf("\nbig_print, usage: bprn input_file");
  49.         exit( 1 );
  50.     }
  51.  
  52.     strcpy( p, argv[1]  );
  53.     strcpy( n, t = get_name( p ) );
  54.     /* xxx schmuddelig */
  55.     *(t-1) = '\0';
  56.  
  57.     text = (char *)load_file( p, n, "r" );
  58.     if( text == NULL )
  59.     {    printf( "\nnot found: %s%s", p, n);
  60.         exit( 2 );
  61.     }
  62.  
  63.     get_text_size( text );
  64.  
  65.     print_text( );
  66.  
  67.     unload_file( text );
  68.  
  69.     return 0;
  70.  
  71. }
  72.  
  73. /*---------------------------------------
  74. | Textgröße ( Zeilen und Spalten ) holen
  75. -----------------------------------------*/
  76. void get_text_size( char *t )
  77. {
  78.     long c;
  79.     int ac;
  80.  
  81.  
  82.     ac = cc = rc = 0;
  83.  
  84.     for( c = 0; c < act_fil_sz; c++)
  85.     {
  86.         if( t[c] == '\n' )
  87.         {    cc = max( ac, cc );
  88.             ac = 0;
  89.             rc++;
  90.         }
  91.     }
  92. }
  93.  
  94.  
  95.  
  96. /*-------------------------
  97. | Text drucken, alle Seiten
  98. ---------------------------*/
  99. void print_text( void )
  100. {
  101.     int row;
  102.     int clm;
  103.  
  104.     row = 0;
  105.  
  106.  
  107.     do
  108.     {
  109.         do
  110.         {
  111.             clm = 0;
  112.  
  113.             print_page( row, clm);
  114.             clm = min( clm + PAPER_CLM, cc );
  115.         }while( clm < cc );
  116.  
  117.         row = min( row + PAPER_ROW, rc);
  118.     }while(    row < rc );
  119. }
  120.  
  121.  
  122.  
  123. /*-------------------
  124. | Seite drucken
  125. |--------------------
  126. | Ab Zeile r
  127. | ab der c'ten Spalte
  128. ---------------------*/
  129. void print_page( int r, int c)
  130. {
  131.     int t;
  132.     long p;
  133.     int y;
  134.  
  135.  
  136.     /*--------------------------
  137.     | PAPER_ROW Zeilen ausgeben,
  138.     | maximal bis Textende!
  139.     ----------------------------*/
  140.     for( y = r; y < r + PAPER_ROW && y < rc; y++ )
  141.     {
  142.         /*-------------------------
  143.         | p auf Zeile #y ausrichten
  144.         ---------------------------*/
  145.         for( p = 0; p < y; p++)
  146.         {    if( text[p] == '\n' )
  147.             {    p--;
  148.             }
  149.         }
  150.  
  151.         /*--------------------------------------
  152.         | In dieser Zeile c Zeichen überspringen
  153.         | maximal bis Zeilenende!
  154.         ----------------------------------------*/
  155.         for( t = 0; t < c; t ++)
  156.         {    if( text[ p + t] == '\n' )
  157.             {    break;
  158.             }
  159.         }
  160.  
  161.  
  162.         /*--------------------------
  163.         | PAPER_CLM Zeichen ausgeben
  164.         ----------------------------*/
  165.         for( ; t < t + PAPER_CLM; t++ )
  166.         {
  167.             /*----------------
  168.             | Zeichen ausgeben
  169.             ------------------*/
  170.             printf("%c", text[ p + t]);
  171.             /*-----------------------
  172.             | Maximal bis Zeilenende!
  173.             -------------------------*/
  174.             if( text[ p + t] == '\n' )
  175.             {    break;
  176.             }
  177.         }
  178.     }
  179. }
  180.